#include <bits/stdc++.h>
using namespace std;

int arr[105][105];
int main() {
    int m, n, ans = 0;
    cin >> m >> n;
    for (int i = 1; i <= m; ++i)
        for (int j = 1; j <= n; ++j)
            cin >> arr[i][j];
    for (int j = 1; j <= n; ++j)
        ans += arr[1][j] + arr[m][j];
    for (int i = 2; i < m; ++i)
        ans += arr[i][1] + arr[i][n];
    cout << ans << endl;
    return 0;
}